//
//  MainViewController.swift
//  SinaWeiBo
//
//  Created by YSH on 16/10/11.
//  Copyright © 2016年 YSH. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {
    
    @objc private func composeDidClick() {
        print(__FUNCTION__)
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        let mainTabBar = MainTabBar()
        //KVC 赋值
        setValue(mainTabBar, forKey: "tabBar")
        // Do any additional setup after loading the view.
        addChildViewController()
        
        print(tabBar.classForCoder)
        mainTabBar.composeBtn.addTarget(self, action: "composeDidClick", forControlEvents: .TouchUpInside)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    private  func addChildViewController() {
        addChildViewController(HomeTableViewController(), title: "首页", imageName: "tabbar_home")
         addChildViewController(MessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
         addChildViewController(DiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
         addChildViewController(ProfileTableViewController(), title: "我", imageName: "tabbar_profile")
    }
    
    private func addChildViewController(childController: UIViewController,title:String,imageName:String) {
        self.tabBar.tintColor = UIColor.orangeColor()
        let nav = UINavigationController(rootViewController: childController)
        
        childController.title = title
        childController.tabBarItem.image = UIImage(named: imageName)
        //childController.tabBarItem.selectedImage = UIImage(named:imageName + "_highlighted")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
       // childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: UIControlState.Selected)
        addChildViewController(nav)

    }
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
